<?php
	header('Content-Type: application/json');

	include_once('../../conn.php');
	
	if ($_SERVER['REQUEST_METHOD'] === 'GET') {
		switch ($_REQUEST['v1']) {
			case 'get_categories':
				$returnObject = get_categories();

				break;
			case 'get_icon_lists':
				$returnObject = get_icon_lists(@$_GET['style']);

				break;
			default:
				$returnObject = (object) array(
					"error_code" => 1001,
					"error_msg" => "未知的api接口",
				);
		}

		echo json_encode($returnObject);
	}

	function get_categories() {
		$result = mysql_query(
								"SELECT
									*
								FROM
									fa5_categories"
		);

		while ($row = mysql_fetch_assoc($result)) {
			$list[] = array(
				"id" => $row['id'],
				"category" => $row['category']
			);
		}

		$returnObject = array(
			"result" => "success",
			"lists" => $list
		);

		mysql_free_result($result);
		mysql_close();

		return $returnObject;
	}

	function get_icon_lists($style = "0") {
		if (!$style) {$style = "0";}

		$query_icon_lists =
							"SELECT
								*
							FROM
								fa5_icons
							WHERE
								style LIKE '%s'";

		$result = mysql_query(sprintf($query_icon_lists, $style));

		while ($row = mysql_fetch_assoc($result)) {
			$list[] = array(
				"id" => $row['id'],
				"name" => $row['name'],
				"style" => $row['style'],
				"category" => $row['category']
			);
		}

		$returnObject = array(
			"result" => "success",
			"lists" => $list
		);

		mysql_free_result($result);
		mysql_close();

		return $returnObject;
	}
?>